﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using FrameWork;
using FrameWork.Components;
using FrameWork.WebControls;


namespace FrameWork.web.Module.ITMS.KnowledgeBase.KBType
{
    public partial class New : System.Web.UI.Page
    {
        int KID;
        protected void Page_Load(object sender, EventArgs e)
        {
            KID = (int)Common.sink("KID", MethodType.Get, 255, 1, DataType.Int);

            BindButton();
            if (!Page.IsPostBack)
            {
                OnStart();
            }
        }

        private void BindButton()
        {
            HeadMenuButtonItem bi0 = new HeadMenuButtonItem();
            bi0.ButtonIcon = "back.gif";
            bi0.ButtonName = "返回";
            bi0.ButtonPopedom = PopedomType.List;
            bi0.ButtonUrl = string.Format("KindList.aspx?KID={0}", KID);
            HeadMenuWebControls1.ButtonList.Add(bi0);


        }

        private void OnStart()
        {
            if (KID == 0)
                G_ParentID_Txt.Text = "类别列表";
            else
            {
                G_ParentID_Txt.Text = BusinessFacade.its_KnowledgeBaseKindDisp(KID).K_KName;
            }

            CatListTitle.Text = string.Format("<a href='KindList.aspx'>类别列表</a>{0}", BusinessFacade.GetKindTitle(KID));
            //Button1.Attributes.Add("Onclick", "javascript:return checkForm(aspnetForm);");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            int RecordCount = 0;
            FrameWorkPermission.CheckPermissionVoid(PopedomType.New);
            its_KnowledgeBaseKind gt = BusinessFacade.its_KnowledgeBaseKindDisp(KID);
            gt.K_KName = (string)Common.sink(G_CName.UniqueID, MethodType.Post, 50, 1, DataType.Str);
            if (gt.KID == 0)
            {
                gt.K_Level = 1;
                BusinessFacade.its_KnowledgeBaseKindList(new QueryParam(), out RecordCount);
                gt.K_ShowOrder = RecordCount + 1;
            }
            else
            {

                gt.K_Level++;
                gt.K_ShowOrder = gt.K_ChildCount + 1;
                gt.K_ChildCount = 0;
                gt.K_ParentID = KID;
            }

            gt.DB_Option_Action_ = "Insert";
            BusinessFacade.its_KnowledgeBaseKindInsertUpdate(gt);
            //更新子部门数
            BusinessFacade.Update_Table_Fileds("its_KnowledgeBaseKind", "K_ChildCount=K_ChildCount+1", string.Format("KID={0}", KID));
            EventMessage.MessageBox(1, "操作成功", string.Format("增加类别({0})成功!", gt.K_KName), Icon_Type.OK, Common.GetHomeBaseUrl(string.Format("KindList.aspx?KID={0}", KID)), Common.BuildJs);
        }
    }
}
